import { App } from 'vue'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
const all_permission = '*:*:*'
/**
 * 用于检查当前用户是否具有所需的权限
 * @param requiredPermissions 
 * @returns 
 */
export function checkPermissions(requiredPermissions: string[]): boolean {
    const { wsCache } = useCache()
    const permissions = wsCache.get(CACHE_KEY.USER)?.permissions || []
  
    const hasPermissions = permissions.some((permission: string) => {
      return all_permission === permission || requiredPermissions.includes(permission)
    })
  
    return hasPermissions
  }
  
  export default {
    install: (app: App) => {
      app.config.globalProperties.checkPermissions = checkPermissions
    }
  }